﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CMS_GYM
{
    public partial class frmUpdateStreet : Form
    {
        #region Khai báo mới
        public Street currentStreet;
        public static bool Success = false;
        #endregion  
        #region Khái báo control

        private NETXP.Controls.XPGroupBox grInfor;
        private System.Windows.Forms.TextBox txtStrtAbbr;
        private System.Windows.Forms.TextBox txtStrtName;
        private System.Windows.Forms.Label lbAbbr;
        private System.Windows.Forms.Label lbName;
        private System.Windows.Forms.ImageList _imageList;
        private System.ComponentModel.IContainer components;
        //──────────────────────────────────────────────────────────────────────────────────────────     
        public frmUpdateStreet()
        {
            InitializeComponent();
            this.Load += new EventHandler(frmUpdateStreet_Load);


        }
        //──────────────────────────────────────────────────────────────────────────────────────────     

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
        //──────────────────────────────────────────────────────────────────────────────────────────     
        #region Windows Form Designer generated code
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmUpdateStreet));
            this._imageList = new System.Windows.Forms.ImageList(this.components);
            this.grInfor = new NETXP.Controls.XPGroupBox();
            this.txtStrtAbbr = new System.Windows.Forms.TextBox();
            this.txtStrtName = new System.Windows.Forms.TextBox();
            this.lbAbbr = new System.Windows.Forms.Label();
            this.lbName = new System.Windows.Forms.Label();
            this.btnExit = new System.Windows.Forms.Button();
            this.btnUpdate = new System.Windows.Forms.Button();
            this.grInfor.SuspendLayout();
            this.SuspendLayout();
            // 
            // _imageList
            // 
            this._imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("_imageList.ImageStream")));
            this._imageList.TransparentColor = System.Drawing.Color.Transparent;
            this._imageList.Images.SetKeyName(0, "");
            this._imageList.Images.SetKeyName(1, "");
            this._imageList.Images.SetKeyName(2, "");
            this._imageList.Images.SetKeyName(3, "");
            this._imageList.Images.SetKeyName(4, "");
            this._imageList.Images.SetKeyName(5, "");
            this._imageList.Images.SetKeyName(6, "");
            this._imageList.Images.SetKeyName(7, "");
            this._imageList.Images.SetKeyName(8, "");
            this._imageList.Images.SetKeyName(9, "");
            this._imageList.Images.SetKeyName(10, "");
            this._imageList.Images.SetKeyName(11, "");
            this._imageList.Images.SetKeyName(12, "");
            this._imageList.Images.SetKeyName(13, "");
            this._imageList.Images.SetKeyName(14, "");
            this._imageList.Images.SetKeyName(15, "");
            // 
            // grInfor
            // 
            this.grInfor.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.grInfor.BackColor = System.Drawing.Color.Transparent;
            this.grInfor.Controls.Add(this.txtStrtAbbr);
            this.grInfor.Controls.Add(this.txtStrtName);
            this.grInfor.Controls.Add(this.lbAbbr);
            this.grInfor.Controls.Add(this.lbName);
            this.grInfor.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.grInfor.Location = new System.Drawing.Point(8, 8);
            this.grInfor.Name = "grInfor";
            this.grInfor.Size = new System.Drawing.Size(304, 72);
            this.grInfor.TabIndex = 0;
            this.grInfor.TabStop = false;
            this.grInfor.Text = "Thông tin";
            // 
            // txtStrtAbbr
            // 
            this.txtStrtAbbr.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.txtStrtAbbr.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtStrtAbbr.Location = new System.Drawing.Point(112, 40);
            this.txtStrtAbbr.Name = "txtStrtAbbr";
            this.txtStrtAbbr.Size = new System.Drawing.Size(176, 20);
            this.txtStrtAbbr.TabIndex = 1;
            // 
            // txtStrtName
            // 
            this.txtStrtName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.txtStrtName.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtStrtName.Location = new System.Drawing.Point(112, 16);
            this.txtStrtName.Name = "txtStrtName";
            this.txtStrtName.Size = new System.Drawing.Size(176, 20);
            this.txtStrtName.TabIndex = 0;
            // 
            // lbAbbr
            // 
            this.lbAbbr.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbAbbr.Location = new System.Drawing.Point(16, 42);
            this.lbAbbr.Name = "lbAbbr";
            this.lbAbbr.Size = new System.Drawing.Size(80, 16);
            this.lbAbbr.TabIndex = 1;
            this.lbAbbr.Text = "Cách viết tắt :";
            // 
            // lbName
            // 
            this.lbName.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbName.Location = new System.Drawing.Point(16, 18);
            this.lbName.Name = "lbName";
            this.lbName.Size = new System.Drawing.Size(88, 17);
            this.lbName.TabIndex = 0;
            this.lbName.Text = "Tên Đường :";
            // 
            // btnExit
            // 
            this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnExit.BackColor = System.Drawing.Color.Transparent;
            this.btnExit.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.btnExit.Location = new System.Drawing.Point(237, 87);
            this.btnExit.Name = "btnExit";
            this.btnExit.Size = new System.Drawing.Size(75, 23);
            this.btnExit.TabIndex = 8;
            this.btnExit.Text = "Thoát";
            this.btnExit.UseVisualStyleBackColor = false;
            // 
            // btnUpdate
            // 
            this.btnUpdate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnUpdate.BackColor = System.Drawing.Color.Transparent;
            this.btnUpdate.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.btnUpdate.Location = new System.Drawing.Point(120, 87);
            this.btnUpdate.Name = "btnUpdate";
            this.btnUpdate.Size = new System.Drawing.Size(75, 23);
            this.btnUpdate.TabIndex = 7;
            this.btnUpdate.Text = "Cập nhật";
            this.btnUpdate.UseVisualStyleBackColor = false;
            // 
            // frmUpdateStreet
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.BackColor = System.Drawing.SystemColors.Control;
            this.ClientSize = new System.Drawing.Size(320, 122);
            this.Controls.Add(this.btnExit);
            this.Controls.Add(this.btnUpdate);
            this.Controls.Add(this.grInfor);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmUpdateStreet";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Cap nhat thong tin duong pho";
            this.grInfor.ResumeLayout(false);
            this.grInfor.PerformLayout();
            this.ResumeLayout(false);

        }
        #endregion
        #endregion
        void frmUpdateStreet_Load(object sender, EventArgs e)
        {
            Success = false;
            if (currentStreet == null) this.Close();

            this.txtStrtName.Text = currentStreet.STRT_NAME;
            this.txtStrtAbbr.Text = currentStreet.STRT_ABBR;
            btnUpdate.Click += new EventHandler(btnUpdate_Click);
            btnExit.Click += new EventHandler(btnExit_Click);
            //this.PhanQuyen();
            SetPermission();
        }
        private void SetPermission()
        {
            btnUpdate.Enabled = clsUser.LayThongTinPhanQuyen("QuanLyDiaChi").ChucNang.Sua;
        }
        void btnExit_Click(object sender, EventArgs e)
        {
            Success = false;
            this.Close();
        }
      
        //──────────────────────────────────────────────────────────────────────────────────────────     
        void btnUpdate_Click(object sender, EventArgs e)
        {
            if (!clsUser.LayThongTinPhanQuyen("QuanLyDiaChi").ChucNang.Sua)
            {
                MessageBox.Show("Người dùng không có quyền thao tác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #region Kiểm tra dữ liệu nhập
            if (txtStrtName.Text.Trim().Equals(""))
            {
                MessageBox.Show("Nhập vào Tên Đường.", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtStrtName.Focus();
                return;
            }

            if (txtStrtAbbr.Text.Trim().Equals(""))
            {
                MessageBox.Show("Nhập vào tên viết tắt.", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtStrtAbbr.Focus();
                return;
            }
           
            #endregion Kiểm tra dữ liệu nhập
            Success = currentStreet.Update(this.txtStrtName.Text.Trim(), this.txtStrtAbbr.Text.Trim());
            //MessageBox.Show(Street.Mess);
            UserControls.hsMessageBox msg = new UserControls.hsMessageBox(Street.Mess, 0.05);
            msg.ShowDialog();
            if (Success) this.Close();

        }

        //private void PhanQuyen()
        //{
        //    btnExit.Enabled = btnUpdate.Enabled = Process.LoginSystem.userLogin.LayPhanQuyen("DIA_CHI");
        //}
    }
}